<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2018/5/29
 * Time: 20:00
 */

namespace app\model;


class Topic extends Model
{
    public function __construct($db)
    {
        parent::__construct($db, "user_material");
    }

    /**
     * 话题视频
     */
    public function topic_video_data($id){
        $this->db->select("id,video_uuid,pic");
        $this->db->from("user_material");
        $this->db->where(["del1" => 2,"examine" =>3,"join_type_sub" =>$id]);
//        $this->db->where(["join_type_sub" =>$id]);
        $this->db->order_by(["add_time" => "desc"]);
        $this->db->limit(10,0);
        $query = $this->db->get();
        $datas = $query->all();
        $data["data"] = $datas;
//        echo $this->db->last_query();exit;
        return $data["data"];
//        return $this->db;
    }

    /**
     * 话题视频
     */
    public function topic_slide($page,$pageSize,$id){
        $this->db->select("id,video_uuid,pic");
        $this->db->from("user_material");
        $this->db->where(["del1" => 2,"examine" =>3,"join_type_sub" =>$id]);
        $this->db->order_by(["add_time" => "desc"]);
        $this->db->limit($pageSize,($page-1)*$pageSize);
        $query = $this->db->get();
        $datas = $query->all();
        $data["data"] = $datas;
//        echo $this->db->last_query();exit;
        return $data["data"];
//        return $this->db;
    }

    /**
     * @param $page
     * @param $pageSize
     * 热门话题
     */
    public function topic_home($length="")
    {
        $this->db->select("id,sub_title,sub_pic,sub_desc,sort");
        $this->db->from("type_sub");
        if(empty($length)){
//            $this->db->where(["del2" => 2, "online" => 2, "is_other!=" =>999999999,"is_xianshi"=>2]);
            $this->db->where(["del2" => 2, "online" => 2, "is_other!=" =>999999999]);
        }else{
//            $this->db->where(["del2" => 2, "online" => 2, "is_other!=" =>999999999,"sort"=>999999999]);
//            $this->db->where(["del2" => 2, "online" => 2, "is_other!=" =>999999999,"sort >"=>4,"is_xianshi"=>2]);
            $this->db->where(["del2" => 2, "online" => 2, "is_other!=" =>999999999,"sort >"=>4]);
        }
        $total = $this->db->count_all_results();
        $this->db->order_by(["sort" => "asc", "add_times" => "desc"]);
        $query = $this->db->get();
        $datas = $query->all();
        $data["total"] = $total;
        $data["data"] = $datas;
//        echo $this->db->last_query();exit;
        return $data;
//        return $this->db;

    }

    /**
     * @param $page
     * @param $pageSize
     * 话题推荐位
     */
    public function topic_recommend()
    {
        $this->db->select("id,sub_title,sub_pic,sub_desc");
        $this->db->from("type_sub");
               $this->db->where(["del2" => 2, "online" => 2, "is_other!=" =>999999999,"sort<="=>4]);
//        $this->db->where(["del2" => 2, "online" => 2, "is_other!=" =>999999999,"sort<="=>4]);
        $total = $this->db->count_all_results();
        $this->db->order_by(["sort" => "asc", "add_times" => "desc"]);
        $query = $this->db->get();
        $datas = $query->all();
        $data["total"] = $total;
        $data["data"] = $datas;
//        echo $this->db->last_query();exit;
        return $data;
//        return $this->db;

    }

    /**
     * 话题分类
     */
    public function topic_class($page,$pageSize,$topic_id){
        $this->db->select("a.id,a.uuid,a.video_uuid,a.pic,a.duration,a.video_url,a.video_desc,a.join_type_sub,a.add_time,a.width2,a.height2,b.nick_name,a.first_pic3,b.nick_pic,c.sub_title");
        $this->db->from("user_material as a");
        $this->db->join("users as b","a.uuid=b.uuid");
        $this->db->join("type_sub as c","a.join_type_sub=c.id");
        $this->db->where(["a.del1"=>2,"a.examine"=>3,"a.join_type_sub"=>$topic_id]);
        $total =  $this->db->count_all_results();
        $this->db->order_by(["type_sub_order"=>"asc","add_time"=>"desc"]);
        $this->db->limit($pageSize,($page-1)*$pageSize);
//        $this->db->limit($pageSize);
        $query =  $this->db->get();
        $datas = $query->all();
        $data["total"] = $total;
        $data["data"] = $datas;
//        echo $this->db->last_query();exit;
        return $data["data"];
    }

    /**
     * 查询单个话题
     */
    public function one_topic($topic_id){
        $this->db->select("id,sub_title,sub_pic,sub_desc");
        $this->db->from("type_sub");
        $this->db->where(["del2" => 2, "online" => 2, "is_other!=" =>999999999,"id"=>$topic_id]);
//        $this->db->where(["online" => 2, "is_other!=" =>999999999,"id"=>$topic_id]);

        $query = $this->db->get();
        $datas = $query->one();
//        echo $this->db->last_query();exit;
        return $datas;
    }

    /**
     * 别人查看视频详情
     */
    public function video_detail($video_uuid,$id){
        $this->db->select("a.id,a.uuid,a.video_uuid,a.pic,a.duration,a.video_url,a.video_desc,a.join_type_sub,a.is_dub,a.quality,a.add_time,a.width2,a.height2,a.first_pic3,a.share_pic,a.count_material_love,a.count_material_share,a.is_wangchun,b.nick_name,b.nick_pic,c.sub_title");
        $this->db->from("user_material as a");
        $this->db->join("users as b","a.uuid=b.uuid");
        $this->db->join("type_sub as c","a.join_type_sub=c.id");
        $this->db->where(["a.del1"=>2,"a.examine"=>3,"a.video_uuid"=>$video_uuid,"a.id"=>$id]);
        $query = $this->db->get();
        $datas = $query->one();
//        echo $this->db->last_query();exit;
        return $datas;
    }

    /**
     * 自己查看自己视频详情
     */
    public function video_details($video_uuid,$id){
        $this->db->select("a.id,a.uuid,a.video_uuid,a.pic,a.duration,a.video_url,a.video_desc,a.join_type_sub,a.is_dub,a.quality,a.add_time,a.width2,a.height2,a.first_pic3,a.share_pic,a.count_material_love,a.count_material_share,a.is_wangchun,b.nick_name,b.nick_pic,c.sub_title");
//        $this->db->select("a.id,a.uuid,a.video_uuid,a.pic,a.duration,a.video_url,a.video_desc,a.join_type_sub,a.is_dub,a.quality,a.add_time,a.width2,a.height2,a.first_pic3,a.share_pic,a.count_material_love,a.count_material_share,b.nick_name,b.nick_pic");
        $this->db->from("user_material as a");
        $this->db->join("users as b","a.uuid=b.uuid");
        $this->db->join("type_sub as c","a.join_type_sub=c.id");
        $this->db->where(["a.del1"=>2,"a.video_uuid"=>$video_uuid,"a.id"=>$id]);
        $query = $this->db->get();
        $datas = $query->one();
//        echo $this->db->last_query();exit;
        return $datas;
    }

    /**
     * 查询点赞了哪些视频
     */
    public function zan($uuid){
        $this->db->select("video_uuid,other_uuid,other_id");
        $this->db->from("material_zan");
        $this->db->where(["my_uuid"=>$uuid]);
        $this->db->order_by(["id"=>"desc"]);
        $query =  $this->db->get();
        $datas = $query->all();
        $data["data"] = $datas;
//        echo $this->db->last_query();exit;
        return $data["data"];
    }

    /**
     * 查询关注了哪些视频
     */
    public function guanzu($uuid){
        $this->db->select("video_uuid,other_uuid");
        $this->db->from("material_follow");
        $this->db->where(["my_uuid"=>$uuid]);
        $this->db->order_by(["id"=>"desc"]);
        $query =  $this->db->get();
        $datas = $query->all();
        $data["data"] = $datas;
//        echo $this->db->last_query();exit;
        return $data["data"];
    }

    /**
     * 查询单个视频
     */
    public function one_love($video_uuid){
        $this->db->select("a.id,a.uuid,a.video_uuid,a.pic,a.duration,a.video_url,a.video_desc,a.join_type_sub,a.is_dub,a.add_time,a.nick_name,a.nick_pic,a.width2,a.height2,a.first_pic3,a.count_material_love,a.count_material_share,b.sub_title");
        $this->db->from("user_material as a");
        $this->db->join("type_sub as b","a.join_type_sub=b.id");
        $this->db->where(["a.del1"=>2,"a.examine"=>3,"a.video_uuid"=>$video_uuid]);
//        $this->db->where(["examine"=>3,"video_uuid"=>$video_uuid]);
        $total =  $this->db->count_all_results();
        $query =  $this->db->get();
        $datas = $query->one();
//        echo $this->db->last_query();exit;
        return $datas;
    }


    /**
     * 查询原始素材的id
     */
    public function erweima_video_detail($ids){
        $this->db->select("a.video_id,a.video_uuid,a.video_big_pic,a.video_small_pic,a.transcode_video_url,a.transcode_video_no_music_url,a.transcode_no_music_zimu_video,a.cut_music_url,a.video_lines,a.video_desc,a.video_time,a.join_time,a.dub_num,a.width,a.height,a.first_pic1,a.video_share_pic,b.sub_title");
        $this->db->from("video as a");
        $this->db->join("type_sub as b","a.video_join_sub=b.id");
        $this->db->where(["status"=>2,"video_type"=>3,"video_id"=>$ids]);
        $query =  $this->db->get();
        $datas = $query->one();
//        echo $this->db->last_query();exit;
        return $datas;
    }

    /**
     * 查询原始素材的id
     */
    public function erweima_user_material_detail($ids){
        $this->db->select("a.id,a.uuid,a.video_uuid,a.pic,a.duration,a.video_url,a.video_desc,a.join_type_sub,a.is_dub,a.quality,a.add_time,a.width2,a.height2,a.first_pic3,a.share_pic,a.count_material_love,a.count_material_share,a.is_wangchun,b.nick_name,b.nick_pic,c.sub_title");
        $this->db->from("user_material as a");
        $this->db->join("users as b","a.uuid=b.uuid");
        $this->db->join("type_sub as c","a.join_type_sub=c.id");
        $this->db->where(["a.del1"=>2,"a.examine"=>3,"a.id"=>$ids]);
        $query = $this->db->get();
        $datas = $query->one();
        return $datas;
    }
}